import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName LC128
 * @Author ykx
 * @Date 2024/6/29 9:14
 * @Version 1.0
 */
public class LC128 {
    public static void main(String[] args) {
        LC128 lc128 = new LC128();
        System.out.println(lc128.longestConsecutive(new int[]{100, 4, 200, 1, 3, 2}));
    }

    public int longestConsecutive(int[] nums) {
        // 声明一个集合，存不同的元素
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }

        // 遍历集合
        int result = 0;
        for (Integer integer : set) {
            if (!set.contains(integer - 1)) {
                int cur_num = integer;
                int cur_result = 1;

                while (set.contains(cur_num + 1)) {
                    cur_num++;
                    cur_result++;
                }
                result = Math.max(result, cur_result);
            }
        }


        return result;
    }

}
